<template>
  <div>
    <el-table :data="tableData">
      <el-table-column prop="action.id" label="订单序号"></el-table-column>
      <el-table-column prop="action.buyTime" label="下单时间"></el-table-column>
      <el-table-column prop="action.result" label="订单状态"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button @click="Showorder(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="readorder" title="历史订单信息查看" :before-close="close1" class="dialog1">
      <template #footer>
        <div class="div3">
          <p>订单序号:{{action.id}}</p>
          <p>商品名:{{ goods.name }}</p>
          <p>单价:{{goods.price}}</p>
          <p>下单时间:{{action.buyTime}}</p>
        </div>
        <div class="div2">
          <p>购买人:{{ user.name }}</p>
          <p>手机号:{{ user.tele }}</p>
          <p>收货地址:{{action.tradePlace}}</p>
        </div>
        <span>
        <el-button @click="close1" class="b3">关闭</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "OrderHistory",
  data(){
    return{
      tableData:[
      ],
      readorder:false,
      action: {},
      goods: {},
      user: {}

    }
  },

  methods:{
    getOrders() {
      request.get("http://localhost:8087/order/viewOrders").then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Showorder(data){
      this.action = data.action
      this.goods = data.goods
      this.readorder=true;
    },
    close1() {
      this.readorder = false;
    },
  },
  created() {
    this.getOrders()
  }
}
</script>

<style scoped>
.div2{
  background-size: 100% ;
  float: left;
  margin-top: -200px;
}
.b3{
  margin-bottom: 20px;
}
.dialog1{
  z-index: 2;
}
</style>
